home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Constructor classes
- Date: 23 Feb 1996 11:38:10 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4gk8v2$2lv@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 22, 1996 17:17:16 in article <Constructor classes>,
- 'scalish@execpc.com (Sherri Scalish)' wrote:
-
-
- >Hope someone can help me, I'm getting very frustrated. I have a container
-
- >class in which I have an array of classes:
- >
- > class OtherClass{
- > private:
- > char m_itema[30];
- > char m_itemb[30];
- > ...
- > }:
- >
- > class ContainerClass{
- > public:
- > OtherClass Items[9];
- > ...
- > };
- >
- >
-
- >How do I access the array's data members?
-
- You can't -- not the way you've declared OtherClass; i.e.,
- the data members are private.
-
- > I have tried:
- > m_itema[0], ContainerClass->m_itema[0], ContainerClass.m_itema[0],
- >OtherClass->m_itema[0]. OtherClass.m_itema[0], etc. etc.
- >
- >I have been working on this for days and am getting truly frustated. I
- >would greatly appreciate an E-Mail to solve this mystery.
- >scalsh@execpc.com. Thanks in advance!!!!
- >
-
- If you declare the data members in OtherClass as public,
- then you can access them as follows:
-
- ContainerClass x, *px;
- x.Items[0].m_itema[20];
- px->Items[8].m_itemb[30];
-
- BTW, I would under most circumstances keep the data members
- private and provide appropriate accessor functions instead. But
- that's strictly a design issue. Just something to think about.
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-